<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    i {
      font-style: normal;
    }
  </style>
</head>

<body>
  <button>赞(<i>0</i>)</button>
  <button>赞(<i>0</i>)</button>
  <button>赞(<i>0</i>)</button>
  <button>赞(<i>0</i>)</button>

  <!-- <script>
    var btns = document.querySelectorAll('button');

    for (let i = 0; i < btns.length; i++) {
      btns[i].onclick = function () {
        var index = this.children[0].innerHTML - 0;
        index++;
        // console.log(btns[i].children[0]);
        btns[i].children[0].innerHTML = index;
      }
    }
  </script> -->
  <script>
    //闭包缓存数据
    function getValue() {
      var value = 1;
      return function () {
        //每一次点击的时候,都应该改变当前点击按钮的value值
        this.innerHTML = "赞(" + (value++) + ")";
      }
    }
    //获取所有的按钮
    var btnObjs = document.getElementsByTagName("button");
    //循环遍历每个按钮,注册点击事件
    for (var i = 0; i < btnObjs.length; i++) {
      //注册事件
      btnObjs[i].onclick = getValue();
    }
  </script>
</body>

</html>